{ This unit is part of Scan Antivirus Present.

    Scan Antivirus Present is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Foobar is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Foobar.  If not, see <http://www.gnu.org/licenses/>.

}
unit uwizard;

{$mode objfpc}
interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  ExtCtrls, ComCtrls, StdCtrls, Buttons;

type

  { Tfwizard }

  Tfwizard = class(TForm)
    ed_net: TEdit;
    ed_domain: TEdit;
    GroupBox1: TGroupBox;
    Image1: TImage;
    img_buil_eicar: TImage;
    img_buil_script: TImage;
    ilist: TImageList;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Memo1: TMemo;
    Memo2: TMemo;
    mresumen: TMemo;
    pcontrol: TPageControl;
    Panel1: TPanel;
    Panel2: TPanel;
    Panel4: TPanel;
    Panel6: TPanel;
    pb_wizard: TProgressBar;
    rb_netview: TRadioButton;
    rb_nbtscan_win: TRadioButton;
    sb_next: TSpeedButton;
    sb_back: TSpeedButton;
    sb_close: TSpeedButton;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    TabSheet3: TTabSheet;
    TabSheet4: TTabSheet;
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure sb_backClick(Sender: TObject);
    procedure sb_closeClick(Sender: TObject);
    procedure sb_nextClick(Sender: TObject);
  private
    //procedure encrypt;
    //procedure dencryp;
    procedure writepatt;
    procedure eicarok;
    procedure eicarfail;
    procedure wrscriptok;
    procedure wrscriptfail;
    procedure writescript;
  public
    { public declarations }
  end; 

var
  fwizard: Tfwizard;
  netwiz : integer;

const
  finaltext = 'The setup wizard is finished.';

implementation

uses umain, umethods,usetting;

{ Tfwizard }

procedure Tfwizard.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
  CloseAction:=caFree;
end;

procedure Tfwizard.FormCreate(Sender: TObject);
begin
{$IFDEF LINUX}
  netwiz:= 2;
{$ENDIF}
{$IFDEF WIN32}
  netwiz:= 1;
{$ENDIF}
ilist.GetBitmap(0,img_buil_eicar.Picture.Bitmap);
end;

procedure Tfwizard.sb_backClick(Sender: TObject);
begin
   case pcontrol.TabIndex of
   1,2 : begin
         pcontrol.TabIndex := 0;
         sb_back.Enabled := False;
         pb_wizard.Position:=0
        end;
   3 : begin
         pcontrol.TabIndex:=netwiz;
         sb_close.Enabled := False;
         sb_next.Enabled:= True;
         pb_wizard.Position:=1;
         mresumen.Lines.Clear
        end;
  end;
end;

procedure Tfwizard.sb_closeClick(Sender: TObject);
begin
  close
end;

procedure Tfwizard.sb_nextClick(Sender: TObject);
begin
  case pcontrol.TabIndex of
    0 : begin
         pcontrol.TabIndex := netwiz;
         sb_back.Enabled := True;
         pb_wizard.Position:=1
        end;
  1,2 : begin
         pcontrol.TabIndex:=3;
         sb_close.Enabled := True;
         sb_next.Enabled:= False;
         pb_wizard.Position:=2;
         writepatt;
         writescript;
         mresumen.Lines.Add('');
         mresumen.Lines.Add(finaltext);
        end;
  end;
end;

procedure Tfwizard.writepatt;
begin
 if write_eicar_file(fmain.workdir+'eicar.com') then
    begin
     Sleep(1000);
     if FileExists(fmain.workdir+'eicar.com') then
        eicarok else
        eicarfail;
    end;
end;

procedure Tfwizard.eicarok;
begin
 mresumen.Lines.Add('* Writing eicar.com OK.');
 ilist.GetBitmap(0,img_buil_eicar.Picture.Bitmap)
end;

procedure Tfwizard.eicarfail;
begin
 mresumen.Lines.Add('* Writing eicar.com failed, please disable Antivirus Realtime Proteccion.');
 ilist.GetBitmap(1,img_buil_eicar.Picture.Bitmap)
end;

procedure Tfwizard.wrscriptok;
begin
 mresumen.Lines.Add('* Writing scripts OK.');
 ilist.GetBitmap(0,img_buil_script.Picture.Bitmap)
end;

procedure Tfwizard.wrscriptfail;
begin
 mresumen.Lines.Add('* Writing scripts failed.');
 ilist.GetBitmap(1,img_buil_script.Picture.Bitmap)
end;

procedure Tfwizard.writescript;
begin
{$IFDEF LINUX}
 //TODO Por implementar
{$ENDIF}
{$IFDEF WIN32}
  if rb_nbtscan_win.Checked then
     if write_bat_nbtscan_win(ed_net.Text,fmain.workdir) then
        begin
         wrscriptok;
         fsettings.set_conf(0,ed_net.Text);
        end else
        wrscriptfail;
  if rb_netview.Checked then
     if write_bat_netview(ed_domain.Text,fmain.workdir) then
        begin
         wrscriptok;
         fsettings.set_conf(1,ed_domain.Text);
        end
        else
        wrscriptfail;
{$ENDIF}
end;


initialization
  {$I uwizard.lrs}

end.

